﻿//===============================================================================
// Microsoft patterns & practices
// Windows Phone 7 Developer Guide
//===============================================================================
// Copyright © Microsoft Corporation.  All rights reserved.
// This code released under the terms of the 
// Microsoft patterns & practices license (http://wp7guide.codeplex.com/license)
//===============================================================================


namespace ConfApp.ViewModels
{
    using System;
    using ConfApp.Services;
    //using TailSpin.PhoneClient.Services.Stores;

    public class ViewModelLocator : IDisposable
    {
        private readonly ContainerLocator containerLocator;
        private bool disposed;

        public ViewModelLocator()
        {
            this.containerLocator = new ContainerLocator();
        }

        public MainViewModel MainViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<MainViewModel>();
            }
        }

        public SessionListViewModel SessionListViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<SessionListViewModel>();
            }
        }

        public SessionDetailsViewModel SessionDetailsViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<SessionDetailsViewModel>();
            }
        }

        public SpeakerListViewModel SpeakerListViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<SpeakerListViewModel>();
            }
        }

        public SpeakerDetailsViewModel SpeakerDetailsViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<SpeakerDetailsViewModel>();
            }
        }

        public PodcastListViewModel PodcastListViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<PodcastListViewModel>();
            }
        }

        public PodcastViewModel PodcastDetailsViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<PodcastViewModel>();
            }
        }

        public Map0ViewModel Map0ViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<Map0ViewModel>();
            }
        }

        public Map1ViewModel Map1ViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<Map1ViewModel>();
            }
        }

        public TrackListViewModel TrackListViewModel
        {
            get
            {
                return this.containerLocator.Container.Resolve<TrackListViewModel>();
            }
        }

        public AppSettingsViewModel AppSettingsViewModel
        {
            get { return this.containerLocator.Container.Resolve<AppSettingsViewModel>(); }
        }

        //public FilterSettingsViewModel FilterSettingsViewModel
        //{
        //    get { return this.containerLocator.Container.Resolve<FilterSettingsViewModel>(); }
        //}

        //public TakeSurveyViewModel TakeSurveyViewModel
        //{
        //    get
        //    {
        //        var templateViewModel = this.SurveyListViewModel.SelectedSurveyTemplate;
        //        var vm = new TakeSurveyViewModel(this.containerLocator.Container.Resolve<INavigationService>())
        //        {
        //            SurveyStoreLocator = this.containerLocator.Container.Resolve<ISurveyStoreLocator>(),
        //            LocationService = this.containerLocator.Container.Resolve<ILocationService>(),
        //            TemplateViewModel = templateViewModel,
        //            SurveyAnswer = this.containerLocator.Container.Resolve<ISurveyStoreLocator>().GetStore().GetCurrentAnswerForTemplate(templateViewModel.Template) ??
        //                           templateViewModel.Template.CreateSurveyAnswers(this.containerLocator.Container.Resolve<ILocationService>())
        //        };
        //        vm.Initialize();
        //        return vm;
        //    }
        //}

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                this.containerLocator.Dispose();
            }

            this.disposed = true;
        }
    }
}
